<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('终端划拨记录列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
         <div class="col-sm-12 search-collapse">
             <form id="formId">
                 <input type="hidden" id="agentNum" name="agentNum" th:value="${agentNum}">
                 <input type="hidden" id="orderNo" name="orderNo"  th:value="${orderNo}">
                 <div class="select-list">
                     <ul>
                         <li>
                             <label style="width: 120px">划拨类型：</label>
                             <select name="type">
                                 <option value="">所有</option>
                                 <option value="5">发货划拨</option>
                                 <option value="6">发货撤销</option>
                             </select>
                         </li>
                         <li class="select-time">
                             <label style="width: 100px;">操作时间：</label>
                             <input type="text" class="time-input" id="startTime" placeholder="开始日期" name="params[beginAddTime]"/>
                             <span>-</span>
                             <input type="text" class="time-input" id="endTime" placeholder="结束日期" name="params[endAddTime]"/>
                         </li>
                         <li>
                             <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                             <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                         </li>
                     </ul>
                 </div>
             </form>
         </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-table-editable-js" />
     <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('terminal:record:edit')}]];
        var removeFlag = [[${@permission.hasPermi('terminal:record:remove')}]];
        var prefix = ctx + "terminal/record";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "终端划拨记录",
                detailView: true,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                queryParams:queryParams,
                columns: [
                {
                    field: 'agentTarNum',
                    title: '服务商编号'
                },
                {
                    field: 'agentTarName',
                    title: '服务商名称'
                },
                {
                    field: 'type',
                    title: '划拨类型',
                    formatter: function (value, row, index) {
                        if(row.type == 5 ){
                            return '<span style="color: purple">发货划入</span>';
                        } else if(row.type == 6 ){
                            return '<span style="color: purple">发货撤销</span>';
                        } else {
                            return '<span style="color: red">未知</span>';
                        }
                    },
                },
                {
                    field: 'total',
                    title: '台数'
                },
                {
                    field: 'serial',
                    title: '批次号',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,25);
                    }
                },
                {
                    field: 'addName',
                    title: '操作服务商名称'
                },
                {
                    field: 'addNo',
                    title: '操作服务商编号'
                },
                {
                    field: 'addDate',
                    title: '操作日期'
                },
                {
                    field: 'addTime',
                    title: '操作时间'
                }]
            };
            $.table.init(options);
        });
        //开启子表
        initChildTable = function(index, row, $detail) {
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable({
                url: ctx + "system/detail/list",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams : {
                    serial: row.serial
                },
                columns: [
                    {
                        field : 'machineNum',
                        title : '机器编号'
                    },
                    {
                        field : 'serial',
                        title : '批次'
                    }]
            });
        };

        function queryParams(params) {
            var search = $.table.queryParams(params);
            search.agentTarNum = $("#agentNum").val();
            search.orderNo = $("#orderNo").val();
            return search;
        }
        function revoke() {
            var url =prefix+ "/revoke";
            $.modal.open("终端撤机" , url, '800','400');
        }

        function downloada() {
            table.set();
            $.get(prefix+"/exportFile", function(result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
            });
        }
    </script>
</body>
</html>